<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('会员商品列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <a class="btn btn-success mr-1" onclick="$.operate.add()">
                <i class="fa fa-plus"></i> 添加
            </a>
            <input type="text" class="form-control mr-1" name="searchKey" placeholder="商品名称">
            <select name="memberType" class="form-control mr-1" th:with="type=${memberType}">
                <option value="">类型</option>
                <option th:each="dict : ${type}" th:text="${dict.title}" th:value="${dict.id}"></option>
            </select>
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i>
                搜索
            </button>
            <button type="button" class="btn btn-default" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>
                重置
            </button>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var prefix = "/member/sale";

    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: prefix + "/list.json",
            createUrl: prefix + "/add.html",
            updateUrl: prefix + "/edit.html?id={id}",
            removeUrl: prefix + "/remove.json",
            modalName: "会员商品",
            columns: [
                {
                    field: 'id',
                    title: 'id'
                },
                {
                    field: 'name',
                    title: '商品名称'
                },
                {
                    field: 'title',
                    title: '类型'
                },
                {
                    field: 'price',
                    align: 'center',
                    title: '价格' ,
                    formatter: function (value, row, index) {
                        return value / 100.0
                    }
                },
                {
                    field: 'days',
                    align: 'center',
                    title: '时长' ,formatter: function (value, row, index) {
                        return value + "天"
                    }
                },
                {
                    field: 'sort',
                    align: 'center',
                    title: '排序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\', \'800px\', \'560px\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>